<!DOCTYPE html>
<html>
<head>
  <title>DOM stress test | anime.js</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta property="og:title" content="anime.js">
  <meta property="og:url" content="http://anime-js.com">
  <meta property="og:description" content="Javascript Animation Engine">
  <meta property="og:image" content="http://anime-js.com/documentation/assets/img/icons/og.png">
  <meta name="twitter:card" content="summary">
  <meta name="twitter:title" content="anime.js">
  <meta name="twitter:site" content="@juliangarnier">
  <meta name="twitter:description" content="Javascript Animation Engine">
  <meta name="twitter:image" content="http://anime-js.com/documentation/assets/img/icons/twitter.png">
  <link rel="apple-touch-icon-precomposed" href="../assets/img/icons/apple-touch-icon.png">
  <link rel="icon" type="image/png" href="../assets/img/icons/favicon.png" >
  <link href="../assets/css/anime.css" rel="stylesheet">
  <script src="../../anime.js"></script>
  <!-- <script src="../assets/js/anime.1.3.js"></script> -->
  <!-- <script src="../assets/js/anime.1.0.js"></script> -->
  <style>

    .particule {
      position: absolute;
      top: 50%;
      left: 50%;
      width: 1rem;
      height: 1rem;
      margin: -.5rem 0 0 -.5rem;
      border: 1px solid currentColor;
      transform: scale(0);
    }

  </style>
</head>
<body></body>
<script>

  var maxElements = Number(location.href.split('?')[1]) || 300;
  var duration = 1500;
  var toAnimate = [];
  var radius = window.innerWidth < window.innerHeight ? window.innerWidth : window.innerHeight;
  var distance = radius / 4 <= 150 ? 150 : radius / 4; 
  var colors = ['#FF1461', '#18FF92', '#5A87FF', '#FBF38C'];

  var createElements = (function() {
    var fragment = document.createDocumentFragment();
    for (var i = 0; i < maxElements; i++) {
      var el = document.createElement('div');
      el.classList.add('particule');
      el.style.color = colors[anime.random(0, 3)];
      toAnimate.push(el);
      fragment.appendChild(el);
    }
    document.body.appendChild(fragment);
  })();

  var animate = function(el, i) {
    var angle = Math.random() * Math.PI * 2;
    anime({
      targets: el,
      translateX: [0, Math.cos(angle) * distance],
      translateY: [0, Math.sin(angle) * distance],
      scale: [
        {value: [0, 1], duration: 400, easing: 'easeOutBack'},
        {value: 0, duration: 400, delay: duration - 800, easing: 'easeInBack'}
      ],
      offset: (duration / maxElements) * i,
      duration: duration,
      easing: 'easeOutSine',
      loop: true
    });
  }

  toAnimate.forEach(animate);

  </script>
  <script src="../assets/js/stats.js"></script>
</html>
